﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Bluyel.Core
{
    /// <summary>
    /// A named data, basic type.
    /// </summary>
    public abstract class DBasicBase : DataNamedBase, IDBasic
    {
        IValueBasic _dVal;

        //---------------------------------------------------------------------
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="name"></param>
        public DBasicBase(string name, IType type)
            : base(name, type)
        {
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="name"></param>
        public DBasicBase(string name, IType type, VarOrConst varOrConst)
            : base(name, type, varOrConst)
        {
        }

        //---------------------------------------------------------------------
        public IValueBasic DVal
        {
            get { return _dVal; }
        }

        //---------------------------------------------------------------------
        public bool SetDVal(IValueBasic dataValue)
        {
            if (dataValue == null)
                return false;

            // check that the type match the defined type
            // TODO:

            _dVal = dataValue;
            return true;
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// exp: 
        /// a=int:12
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            string s=Name + "=";
            if (_dVal == null)
                s += Type.ToString() + "(null)";
            else
            s += _dVal.ToString();
            return s;
        }
    }
}
